import { defineStore } from 'pinia'
import { ref } from 'vue'

export const useUserStore = defineStore(
  'user',
  () => {
    const userInfo = ref(null)
    // 设置用户信息
    const setUserInfo = (value) => {
      userInfo.value = value
      localStorage.setItem('user', JSON.stringify(userInfo.value))
    }
    const removeUserInfo = () => {
      userInfo.value = null
      localStorage.removeItem('user')
    }

    return { userInfo, setUserInfo, removeUserInfo }
  },
  {
    persist: true,
  },
)
